﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;


namespace WPFExcelReport
{
    public partial class TYLGB02:ViewBase  
    { 
        ITXEXRPT ITXEXRPT;
        public TYLGB02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGLLG();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            base.Window_Loaded(sender, e);

        } 
        private void txtLO_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
           if (e.Key == Key.Enter)
           {
                this.Focus();
                QueryCommand(null, null);
            }
        }
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            int tBOX = 0; double TQ = 0;
            DataSet Result;
            DataSet Return = new DataSet(); 
            if (LP== "")
            {
                LP = "AAA";
            }
            else
            {
                LP = Helper.Left(LP + "        ", 8);
            }
            dwData = TBMain.NewRow();
            dwData["GLLO"] = LO;
            dwData["GLLB"] = LB;
            dwData["GLLP"] = LP;
            dwData["GLLBEH"] = KEY1;
            dwData["GLLBEHI"] = KEY2;
            dwData["GLOWNER"] = ART;
            dwData["GLFILLER1"] = FARBE; 
            try
            {
                Result = ((VGLLG)MV).QueryGLLG(dwData, 8);
                MergeData(Result, true, true);
                
                foreach (DataRow row in Result.Tables[0].Rows)
                {
                    tBOX  += Convert.ToInt32(row["GLBSTSP"].ToString());
                    TQ += Convert.ToDouble(row["GLBSTKG"].ToString());
                }
                SBOX.Text =tBOX.ToString();
                SQT.Text = TQ.ToString();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            if (LP == "AAA")
            {
                LP = "";
            }

        }
         
        private void PrintCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = MV.SetProd;
                //ITXEXRPT.dsSource.Merge(SetEnv);

                ITXEXRPT.DocType = "YGRYLGB02";

                ITXEXRPT.strExcelFile = @"\YGR\YGRSTOCK.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
}
